package com.work.flow.common;

import java.util.HashMap;
import java.util.Map;

public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R() {
        this.put((String)"code", 0);
        this.put((String)"msg", "操作成功");
    }

    public static R error() {
        return error(500, "操作失败");
    }

    public static R operate(boolean b) {
        return b ? ok() : error();
    }

    public static R error(String msg) {
        return error(500, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put((String)"code", code);
        r.put((String)"msg", msg);
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put((String)"msg", msg);
        return r;
    }

    public static R ok(Map<String, Object> map) {
        R r = new R();
        r.putAll(map);
        return r;
    }

    public static R ok() {
        return new R();
    }

    public static R error401() {
        return error(401, "你还没有登录");
    }

    public static R error403() {
        return error(403, "你没有访问权限");
    }

    public static R data(Object data) {
        return ok().put("data", data);
    }

    public static R page(Object page) {
        return ok().put("page", page);
    }

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
